package com.woniuxy.carrental.service.impl;

import com.woniuxy.carrental.entity.PageBean;
import com.woniuxy.carrental.entity.ResponseResult;
import com.woniuxy.carrental.entity.Wareing;
import com.woniuxy.carrental.mapper.WareingMapper;
import com.woniuxy.carrental.service.WareingService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author author
 * @create 2021-10-12 11:05
 */
@Service
public class WareingServiceImpl implements WareingService {
    //获取mapper实例
    @Resource
    WareingMapper wareingMapper;
    
    //分页查询表中数据
    @Override
    public ResponseResult<PageBean<Wareing>> selectDetailsByPageService(Wareing wareing,
    int pageIndex, int pageSize) {
        //使用工具类pagebean
        PageBean<Wareing> pageBean = new PageBean<>();
        //调用方法获得数据
        List<Wareing> wareings = wareingMapper.selectWareingByPage(wareing, pageIndex, pageSize);
       //获取数据条数
        int i = wareingMapper.selectCountWareingByPage(wareing);
        //向pegebean中添加数据
        pageBean.setBeanList(wareings);
        pageBean.setPageIndex(pageIndex);
        pageBean.setPageSize(pageSize);
        pageBean.setTotalRecord(i);
        return new ResponseResult<PageBean<Wareing>>(pageBean, 200, "O得K");
    }

    //删除表中数据根据id
    @Override
    public void deleteWareingService(String wareingid) {
        wareingMapper.deleteWareingMapper(wareingid);
    }
}
